package com.jy.controller;


import com.jy.common.enums.ResponseWrapper;
import com.jy.common.model.user.param.AddAddressParam;
import com.jy.common.model.user.param.DeleteAddressParam;
import com.jy.common.tool.CommonTool;
import com.jy.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 用户的地址表 前端控制器
 * </p>
 *
 * @author fzg
 * @since 2025-01-16
 */
@RestController
@RequestMapping("/address")
public class AddressController {

    private final AddressService addressService;

    public AddressController(AddressService addressService) {
        this.addressService = addressService;
    }


    /**
     * 获取我的地址列表
     * @param request request
     * @return ResponseWrapper
     */
    @GetMapping("/getAddressList")
    public ResponseWrapper getAddressList(HttpServletRequest request){
        return addressService.getAddressList(CommonTool.getUserAidByToken(request));
    }



    /**
     * 根据地址aid获取地址信息
     * @return ResponseWrapper
     */
    @GetMapping("/getAddressInfoByAid")
    public ResponseWrapper getAddressInfoByAid(@RequestParam Integer addressAid){
        return addressService.getAddressInfoByAid(addressAid);
    }



    /**
     * 添加地址
     * @param request request
     * @return ResponseWrapper
     */
    @PostMapping("/addAddress")
    public ResponseWrapper addAddress(HttpServletRequest request, @RequestBody @Validated AddAddressParam param){
        return addressService.addAddress(CommonTool.getUserAidByToken(request),param);
    }


    /**
     * 删除地址
     * @return ResponseWrapper
     */
    @PostMapping("/deleteAddress")
    public ResponseWrapper deleteAddress(@RequestBody @Validated DeleteAddressParam param){
        return addressService.deleteAddress(param);
    }




}
